//
//	RModel.swift
//	Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport

import Foundation 
import VTO2Lib

class RModel : NSObject, NSCoding{
    
    var hr : Int!
    var spo2 : Int!
    var timeStamp : TimeInterval!
    var vector : Int!
    var notes : [String]?
    var identifiers : String!
    var deviceName : String!
    var sn : String!
    var hadUpload = false
    
    
    init(fromeLocal obj: Int) {
        hr = Int(0)
        spo2 = Int(0)
        vector = Int(0)
        timeStamp = TimeInterval(obj)
        if let device = RManager.manager.currentDevice {
            identifiers = device.identifiers
            deviceName = device.advName
        }else {
            identifiers = ""
            deviceName = ""
        }
        if let info = RManager.manager.info {
            sn = info.sn
        }else {
            sn = ""
        }
    }
    
    init(waveObj obj: VTO2WaveObject, time: Int) {
        hr = Int(obj.hr)
        spo2 = Int(obj.spo2)
        vector = Int(obj.ac_v_s)
        print(time)
        timeStamp = TimeInterval(time)
        if let device = RManager.manager.currentDevice {
            identifiers = device.identifiers
            deviceName = device.advName
        }else {
            identifiers = ""
            deviceName = ""
        }
        if let info = RManager.manager.info {
            sn = info.sn
        }else {
            sn = ""
        }
    }
    
    init(fromVTObjectr obj: VTRealObject) {
        hr = Int(obj.hr)
        spo2 = Int(obj.spo2)
        vector = Int(obj.vector)
        timeStamp = Date.init().timeIntervalSince1970
        hadUpload = false
        if let device = RManager.manager.currentDevice {
            identifiers = device.identifiers
            deviceName = device.advName
        }else {
            identifiers = ""
            deviceName = ""
        }
        if let info = RManager.manager.info {
            sn = info.sn
        }else {
            sn = ""
        }
    }
    
    /**
     * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
     */
    func toDictionary() -> [String:Any]
    {
        var dictionary = [String:Any]()
        if hr != nil{
            dictionary["hr"] = hr
        }
        if spo2 != nil{
            dictionary["spo2"] = spo2
        }
        if timeStamp != nil{
            dictionary["timeStamp"] = timeStamp
        }
        if vector != nil{
            dictionary["vector"] = vector
        }
        if notes != nil {
            dictionary["notes"] = notes
        }
        if identifiers != nil {
            dictionary["identifiers"] = identifiers
        }
        if deviceName != nil {
            dictionary["deviceName"] = deviceName
        }
        if sn != nil {
            dictionary["sn"] = sn
        }
        return dictionary
    }
    
    /**
     * NSCoding required initializer.
     * Fills the data from the passed decoder
     */
    @objc required init(coder aDecoder: NSCoder)
    {
        hr = aDecoder.decodeObject(forKey: "hr") as? Int
        spo2 = aDecoder.decodeObject(forKey: "spo2") as? Int
        timeStamp = aDecoder.decodeObject(forKey: "timeStamp") as? TimeInterval
        vector = aDecoder.decodeObject(forKey: "vector") as? Int
        notes = aDecoder.decodeObject(forKey: "notes") as? [String]
        identifiers = aDecoder.decodeObject(forKey: "identifiers") as? String
        deviceName = aDecoder.decodeObject(forKey: "deviceName") as? String
        sn = aDecoder.decodeObject(forKey: "sn") as? String
    }
    
    /**
     * NSCoding required method.
     * Encodes mode properties into the decoder
     */
    func encode(with aCoder: NSCoder)
    {
        if hr != nil{
            aCoder.encode(hr, forKey: "hr")
        }
        if spo2 != nil{
            aCoder.encode(spo2, forKey: "spo2")
        }
        if timeStamp != nil{
            aCoder.encode(timeStamp, forKey: "timeStamp")
        }
        if vector != nil{
            aCoder.encode(vector, forKey: "vector")
        }
        if notes != nil {
            aCoder.encode(notes, forKey: "notes")
        }
        if identifiers != nil {
            aCoder.encode(identifiers, forKey: "identifiers")
        }
        if deviceName != nil {
            aCoder.encode(deviceName, forKey: "deviceName")
        }
        if sn != nil {
            aCoder.encode(sn, forKey: "sn")
        }
        
    }
    
}
